using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame1
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class CowboyGame : Microsoft.Xna.Framework.Game
    {
        public static bool IsPaused;

        private readonly GraphicsDeviceManager _graphics;
        private SpriteBatch _spriteBatch;

        private static Dictionary<Screens, IGameScreen> _gameScreens = new Dictionary<Screens, IGameScreen>();
        public static Screens CurrentScreen = Screens.MenuScreen;

        public CowboyGame()
        {
            _graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            _graphics.PreferredBackBufferHeight = 400;
            _graphics.PreferredBackBufferWidth = 800;
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);
            _gameScreens.Add(Screens.GameScreen, new GameWorldScreen(_graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight, Content, this));
            _gameScreens.Add(Screens.MenuScreen, new MenuScreen(_graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight, Content, this));
        }

        

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //Debug.WriteLine(GetScreenRect(hero.rect));

            //#if DEBUG

            //#endif

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();


            KeyboardState keyState = Keyboard.GetState();
  
              
            _gameScreens[CurrentScreen].Update(gameTime, keyState);
            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            if (IsPaused)
            SuppressDraw();
            

            _gameScreens[CurrentScreen].Draw(_spriteBatch);

            base.Draw(gameTime);
        }
    }
}
